package com.itheima.hashset;

import com.itheima.domain.Student;

import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

/*
使用hashSet存储学生对象
 */
public class Demo01 {

    public static void main(String[] args) {
        HashSet<Student> set = new HashSet<>();
        Student lu = new Student("鹿晗", 28);
        Student guan = new Student("关晓彤", 22);
        Student wu = new Student("吴亦凡", 27);
        Student cai = new Student("蔡徐坤", 28);
        Student cai2 = new Student("蔡徐坤", 28);
        set.add(lu);
        set.add(guan);
        set.add(wu);
        set.add(cai);
        set.add(cai2);


        System.out.println(cai.hashCode()==cai2.hashCode());
        System.out.println(cai.equals(cai2));
        Iterator<Student> iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("========================");
        for (Student student : set) {

            System.out.println(student);
        }

        System.out.println("=================");
        //使用foreach 方法
        set.forEach(t-> System.out.println(t));

    }
}
